package com.example.lenovo.a203_yhy_ordering_3.model;

import com.example.lenovo.a203_yhy_ordering_3.beans.AllUserCollectBean;
import com.example.lenovo.a203_yhy_ordering_3.beans.UserCollectShopBean;
import com.example.lenovo.a203_yhy_ordering_3.iface.AllUserCollectIface;
import com.example.lenovo.a203_yhy_ordering_3.listener.AllUserCollectListener;
import com.example.lenovo.a203_yhy_ordering_3.service.AllUserCollectService;
import com.example.lenovo.a203_yhy_ordering_3.service.UserCollectShopService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by lenovo on 2018/12/5.
 */

public class AllUserCollectModel implements AllUserCollectIface{


    private Retrofit retrofit;

    public AllUserCollectModel(){
        retrofit=new Retrofit.Builder()
                .baseUrl("http://172.24.10.175:8080/foodService/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    @Override
    public void getAllUserCollectResult(int user_id, int flag, final AllUserCollectListener allUserCollectListener) {
        AllUserCollectService allUserCollectService=retrofit.create(AllUserCollectService.class);
        Call<List<AllUserCollectBean>> call=allUserCollectService.getAllUserCollection(user_id,flag);
        call.enqueue(new Callback<List<AllUserCollectBean>>() {
            @Override
            public void onResponse(Call<List<AllUserCollectBean>> call, Response<List<AllUserCollectBean>> response) {
                if(response.isSuccessful()&&response!=null)
                    allUserCollectListener.onResponse(response.body());
                else
                    allUserCollectListener.onFail("fail");
            }

            @Override
            public void onFailure(Call<List<AllUserCollectBean>> call, Throwable t) {
                allUserCollectListener.onFail(t.toString());
            }
        });
    }
}
